package net.dreamlu.car.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import net.dreamlu.car.model.Car;
import net.dreamlu.car.service.CarInfoMenuService;
import net.dreamlu.car.service.CarService;
import net.dreamlu.common.base.BaseController;
import net.dreamlu.common.result.EasyPage;
import net.dreamlu.common.result.PageVO;
import net.dreamlu.common.result.Tree;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Controller
@RequestMapping("/car")
@RequiredArgsConstructor
public class CarController extends BaseController {
	private final CarInfoMenuService carInfoMenuService;
	private final CarService carService;

	@ApiIgnore
	@GetMapping("/list")
	public String manager() {
		return "system/car/list";
	}

	@PostMapping("/dataGrid")
	@ResponseBody
	public EasyPage<Car> dataGrid(Car role, PageVO pageVO) {
		QueryWrapper<Car> ew = new QueryWrapper<>(role);
		Page<Car> pages = pageVO.toPage();
		carService.page(pages, ew);
		return EasyPage.of(pages);
	}

	@ApiIgnore
	@GetMapping("/infoTree")
	public String infoTree() {
		return "system/car/tree";
	}

	@ApiIgnore
	@GetMapping("/info")
	public String info() {
		return "system/car/info";
	}

	@PostMapping(value = "/tree")
	@ResponseBody
	public List<Tree> tree() {
		return carInfoMenuService.selectTree();
	}
}
